//获取应用实例
const app = getApp();
// 引入AES.js
var baseJs = require("../../common/base.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    uid: "",
    userType: "",
    updateName: "",
    updateFlag: true,
    addFlag: true,
    pageIndex: 1,
    state: "",
    clockList: [],
    typename: '',
    name: '',

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      uid: wx.getStorageSync('uid'),
      userType: wx.getStorageSync('userType')
    })
    this.GetCustomGoodsType();

  },
  // 获取分组产品列表
  GetCustomGoodsType: function () {
    var that = this;
    var uid = this.data.uid;
    var pageIndex = this.data.pageIndex;
    var clockList = this.data.clockList;
    wx.request({
      url: baseJs.api + baseJs.encryUrl("method=BusinessGetCustomGoodsType&UID=" + uid + "&PageSize=10&PageIndex=" + pageIndex),
      success: function (res) {
        var json = JSON.parse(baseJs.decryUrl(res.data)).ResultData;
        for (var i = 0; i < json.length; i++) {
          clockList.push(json[i])
        }
        that.setData({
          clockList: clockList,
        })
        if (json.length == 10) {
          that.setData({
            state: 'loadMore',
          })
        } else if (json.length == 0 && pageIndex == 1) {
          that.setData({
            state: 'noData',
          })
        } else if (json.length < 10) {
          that.setData({
            state: 'noMore',
          })
        } else if (json.length == 0 && pageIndex > 1) {
          that.setData({
            state: 'noMore',
          })
        }
        console.log(clockList);
      }
    })

  },
  //获取产品名称
  NameInput: function (e) {
    console.log(e)
    this.setData({
      typename: e.detail.value,
    })
  },

  // 新增分组--保存
  formSubmit: function () {
    var that = this;
    var uid = this.data.uid;
    var typename = this.data.typename;
    console.log("method=BusinessCustomGoodsType&UID=" + uid + "&TypeName=" + typename);
    wx.request({
      url: baseJs.api + baseJs.encryUrl("method=BusinessCustomGoodsType&UID=" + uid + "&TypeName=" + typename),
      success: function (res) {
        var json = JSON.parse(baseJs.decryUrl(res.data));
        typename = json.ResultData.TypeName;
        that.setData({
          // typename: typename,
        })
        console.log(json);

        if (json.ResultFlag == 1) {
          wx.showToast({
            title: '添加成功',
            icon: 'none',
            duration: 2000
          });
          setTimeout(function () {
            wx.navigateBack({
              delta: 1
            })
          }, 1000)
        } else {
          wx.showToast({
            title: json.ResultMsg,
            icon: 'none',
            duration: 2000
          });
        }
      }
    })

  },

})